﻿using System;
using System.Threading;

namespace EasyConveyor.TestClient
{
	public static class Program
	{
		public static void Main()
		{
			var cancellationToken = new CancellationToken();

			var rapidBuilder = new PipelineBuilder(20, new RapidActivator(cancellationToken))
			{
				Logger = Console.WriteLine
			};
			rapidBuilder.AddMiddleware(typeof(RapidStep1Middleware));
			rapidBuilder.AddMiddleware(typeof(RapidStep2Middleware));
			rapidBuilder.AddMiddleware(typeof(RapidStep3Middleware));

			var slowBuilder = new PipelineBuilder(20, new SlowActivator(cancellationToken))
			{
				Logger = Console.WriteLine
			};
			slowBuilder.AddMiddleware(typeof(SlowStep1Middleware));
			slowBuilder.AddMiddleware(typeof(SlowStep2Middleware));

			var application = new Application(rapidBuilder, slowBuilder);

			application.Error += ApplicationOnError;
			application.RequestCompleted += ApplicationOnRequestCompleted;
			application.RequestReceived += ApplicationOnRequestReceived;

			Console.ReadKey();

			application.RequestReceived += ApplicationOnRequestReceived;
			application.RequestCompleted += ApplicationOnRequestCompleted;
			application.Error += ApplicationOnError;
		}

		private static void ApplicationOnRequestReceived(object sender, RequestReceivedEventArgs requestReceivedEventArgs)
		{
			//System.Diagnostics.Debug.WriteLine("RECEIVED: " + requestReceivedEventArgs.Context);
		}

		private static void ApplicationOnRequestCompleted(object sender, RequestCompletedEventArgs requestCompletedEventArgs)
		{
			//System.Diagnostics.Debug.WriteLine("COMPLETED: " + requestCompletedEventArgs.Context);
		}

		private static void ApplicationOnError(object sender, MiddlewareErrorEventArgs middlewareErrorEventArgs)
		{
			//System.Diagnostics.Debug.WriteLine("ERROR: " + middlewareErrorEventArgs.Exception);
		}
	}
}
